package com.xyh;


import com.netflix.client.ClientFactory;
import com.netflix.client.http.HttpRequest;
import com.netflix.client.http.HttpResponse;
import com.netflix.config.ConfigurationManager;
import com.netflix.niws.client.http.HttpClientRequest;
import com.netflix.niws.client.http.RestClient;

import java.net.URI;

public class TestRibbon {

    public  static void main(String[] args) throws  Exception{
        ConfigurationManager.getConfigInstance().setProperty("my-client.ribbon.listOfServers","localhost:8080,localhost:8081");
        RestClient client = (RestClient) ClientFactory.getNamedClient("my-client");
        HttpRequest request = HttpRequest.newBuilder().uri("/persion").build(); // 3
        for (int i = 0; i < 20; i++)  {
            HttpResponse response = client.executeWithLoadBalancer(request); // 4
            String json = response.getEntity(String.class);
            System.out.print(json+"输出");
      //      System.out.println("Status code for " + response.getRequestedURI() + "  :" + response.getStatus());
        }
    }
}
